<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改专利软著')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-zhuanliruanzhu-edit" th:object="${sciZhuanliruanzhu}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group row">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">学院：</label>
                    <div class="col-sm-8">
                        <select name="xueyuan" class="form-control" th:with="type=${@dict.getType('sys_dept')}" required disabled="true">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{xueyuan}"></option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">姓名：</label>
                    <div class="col-sm-8">
                        <select name="userId" class="form-control" disabled="true">
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ user.userId == sciZhuanliruanzhu.userId}"></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">名称：</label>
                    <div class="col-sm-8">
                        <input name="mingcheng" th:field="*{mingcheng}" class="form-control" type="text" required maxlength="50">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">分类：</label>
                    <div class="col-sm-8">
                        <select name="fenlei" class="form-control" th:with="type=${@dict.getType('sys_zhuanli_fenlei')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{fenlei}"></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">授权号：</label>
                    <div class="col-sm-8">
                        <input name="shoquanhao" th:field="*{shoquanhao}" class="form-control" type="text" required maxlength="20">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">获批时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="huopishijain" th:value="${#dates.format(sciZhuanliruanzhu.huopishijain, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">是否应用：</label>
                    <div class="col-sm-8" th:with="type=${@dict.getType('sys_yes_no')}">
                        <label th:each="dict : ${type}" class="check-box">
                            <input name="shifouyingyon" type="radio" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${sciZhuanliruanzhu.shifouyingyon.contains(dict.dictValue)?true:false}">
                        </label>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">是否行业联合：</label>
                    <div class="col-sm-8" th:with="type=${@dict.getType('sys_yes_no')}">
                        <label th:each="dict : ${type}" class="check-box">
                            <input name="hangyelianhe" type="radio" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${sciZhuanliruanzhu.hangyelianhe.contains(dict.dictValue)?true:false}">
                        </label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">排名：</label>
                    <div class="col-sm-8">
                        <select name="paiming" class="form-control" th:with="type=${@dict.getType('sys_zhuanliruanzhu_fzr')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label is-required">专利软著文件：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="wenjian" th:field="*{wenjian}">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="wenjian" name="file" type="file">
                        </div>
                    </div>
                </div>

                <div class="col-sm-6">
                    <!-- 可以在这里添加另一个输入框，如果没有则留空 -->
                </div>
            </div>

        </form>

        <h4 class="form-header h4">批阅记录</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()">  </i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"> 关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/zhuanliruanzhu";

        $(document).ready(function() {
            var kid = $("#id").val();
            var options = {
                url: prefix + "/bhyy/" + kid,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pagination: false,
                columns: [

                    {
                        field: 'createTime',
                        title: '批阅时间',
                        width: 200

                    },
                    {
                        field: 'uname',
                        title: '批阅人',
                        width: 100
                    },
                    {
                        field: 'concate',
                        title: '内容',
                        width: 500
                    },
                    {
                        field: 'state',
                        title: '审核状态',
                        width: 100
                    }]
            };

            $.table.init(options);
        });

        $("#form-zhuanliruanzhu-edit").validate({
            focusCleanup: true
        });



        function submitHandler() {
            if ($.validate.form()) {
                // 检查文件输入框的值，而不是隐藏字段
                if ($("input[name='wenjian']").val() == "")
                    return $.modal.alertError("请上传专利文件");
                $.operate.saveTab(prefix + "/edit", $('#form-zhuanliruanzhu-edit').serialize());
            }
        }


        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            var initialPreview = [];
            var initialPreviewConfig = [];
            
            if (val && val.trim() !== '') {
                initialPreview = [val];
                initialPreviewConfig = [{
                    type: "pdf",
                    caption: val.split('/').pop(),
                    url: ctx + "common/delete",
                    key: val
                }];
            }
            
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload/zlrz',
                initialPreviewAsData: true,
                initialPreview: initialPreview,
                initialPreviewConfig: initialPreviewConfig,
                maxFileCount: 1,
        maxFileSize: 51200,
                autoReplace: true,
                overwriteInitial: true,
                allowedFileExtensions: ["pdf"],
                slugCallback: function(filename) {
                    if ($("input[name='mingcheng']").val()===""){
                        $(".file-upload").fileinput('clear');
                        $.modal.alertError("请先输入名称");
                        return false;
                    }
                    // 自定义文件名生成规则
                    fileExtension = filename.split('.').pop();
                    const year = new Date().getFullYear();
                    const newName = year +"-"+ $("input[name='mingcheng']").val() +"-"+ "专利软著文件"+ "." + fileExtension;
                    return newName;
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                if (data.response && data.response.url) {
                    $("input[name='" + event.currentTarget.id + "']").val(data.response.url);
                }
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('');
            }).on('fileclear', function (event) {
                $("input[name='" + event.currentTarget.id + "']").val('');
            });
            $(this).fileinput('_initFileActions');
        });


        $("input[name='huopishijain']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

    </script>
</body>
</html>